<template>
  <div class="electronicTagWrap">
    <div class="pageTableInner">
      <div class="infoSearchWrap">
        <div class="infoSearchOne">
          <el-row :gutter="20">
            <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">标签状态:</span>
                <span class="searchInputFont">
                    <el-select v-model="searchInfo.labelStatus" @change="searchRowsInfo" size="mini" clearable placeholder="全部">
                       <el-option
                         v-for="item in options"
                         :key="item.value"
                         :label="item.label"
                         :value="item.value">
                        </el-option>
                    </el-select>
                </span>
              </div>
            </el-col>
            <el-col :span="6">
              <div class="searchWrap">
                <span class="searchFont">投放行政区:</span>
                <span class="searchInputFont">
                     <el-select v-model="searchInfo.putDistrict" @change="changeDistrict(searchInfo.putDistrict)" size="mini"
                                :disabled="$store.state.userInfo.regionId?true:false"  clearable placeholder="行政区">
                    <el-option
                      v-for="item in $store.state.districtData"
                      :key="item.id"
                      :label="item.regionName"
                      :value="item.id">
                    </el-option>
                  </el-select>
                </span>
              </div>
            </el-col>
            <el-col :span="5">
              <div class="searchWrap">
                <span class="searchFont">标签编号:</span>
                <span class="searchInputFont">
                    <el-input clearable size="mini" v-model="searchInfo.labelNo" @change="searchRowsInfo" auto-complete="off" placeholder="标签编号"></el-input>
                </span>
              </div>

            </el-col>
            <div style="float: right;margin-right: 10px;">
              <el-button type="primary" size="mini" @click="searchRowsInfo()">查询</el-button>
            </div>
          </el-row>
        </div>
      </div>
      <div class="tableContainer">
        <div class="tableInner">
          <el-table
            ref="multipleTable"
            :data="rows"
            stripe
            :height="tableHeight"
            tooltip-effect="dark"
            style="width: 100%"
          >

            <el-table-column
              label="标签编号"
              prop="labelNo"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="标签蓝牙"
              prop="labelMac"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="初次投放行政区"
              prop="putDistrictName"
              show-overflow-tooltip>
            </el-table-column>
            <el-table-column
              label="车辆编号"
              prop="vehicleNo"
              show-overflow-tooltip
            >
            </el-table-column>
            <el-table-column
              label="车辆企业"
              prop="enterpriseNo"
              show-overflow-tooltip>

            </el-table-column>
            <el-table-column
              label="标签状态"
              prop="labelStatus"
              show-overflow-tooltip>
              <template slot-scope="scope">
                {{scope.row.labelStatus == 0 ? "正常" : scope.row.labelStatus == 1 ? "维修" :scope.row.labelStatus == 2 ? "报废" : ""}}
              </template>
            </el-table-column>
          </el-table>
        </div>
        <div class="paginationWrap" >
          <el-row :gutter="10">
            <el-col :span="13" :offset="9">
              <el-pagination
                @size-change="handleSizeChange"
                @current-change="handleCurrentChange"
                :current-page="currentPage"
                :page-sizes="[10, 30, 50, 100,200]"
                :page-size="pageSize"
                layout="total, sizes, prev, pager, next, jumper"
                :total="count">
              </el-pagination>
            </el-col>
          </el-row>
        </div>

      </div>
    </div>
  </div>
</template>

<script>


  export default {
    props: [],
    data(){
      return {
        options: [
          {
            value: '0',
            label: '正常'
          }, {
            value: '1',
            label: '维修'
          }, {
            value: '2',
            label: '报废'
          },],
        streetData: [],
        rows: [],
        pageSize: 10,
        count: 0,
        currentPage: 1,
        tableHeight: 400,
        checkInfo: {},
        searchInfo: {
          street: "",
          putDistrict: this.$store.state.userInfo.regionId,
          labelStatus: "",
          labelNo: "",
          sortType: "",
          asc: "true"
        },
      }
    },
    components: {},
    created(){
      this.searchRowsInfo()
    },
    mounted(){
      this.$nextTick(() => {
        //表格高度
        this.tableHeight = document.querySelector(".electronicTagWrap").clientHeight - 160
      })
    },

    methods: {
      pushAndGet(row){
        this.checkInfo=row
        this.$router.push("/parkingArea/parkSet")
      },
      handleDelete(row){
        this.$confirm('确认删除用户 “' + row.labelNo + '” , 是否继续?', '提示', {
          confirmButtonText: '确定',
          cancelButtonText: '取消',
          type: 'warning'
        }).then(() => {
          this.axios.post(process.env.API_HOST + `/area/deleteGovArea`,{id:row.id})
            .then(response => {
              const result = response.data
              if (result.code === 200) {
                this.searchRowsInfo()
                this.$message({
                  type: 'success',
                  message: '删除成功!'
                });
              }
            })

        }).catch(() => {

        });
      },
      //获取街道
      changeDistrict(putDistrict){
        this.searchRowsInfo()
        this.axios.post(process.env.API_HOST + '/common/selectRegion?',{parentId:putDistrict})
          .then(response => {
            const result = response.data
            if (result.code == 200) {
              this.streetData = result.result
            }
          })
      },
      //排序
      sortChange(a) {
        if (a.column) {
          if (a.column.label == "电子标签") {
            this.searchInfo.asc = !this.searchInfo.asc
            this.searchInfo.sortType = "labelNo"
            this.searchRowsInfo()
          } else if (a.column.label == "车辆编号") {
            this.searchInfo.asc = !this.searchInfo.asc
            this.searchInfo.sortType = "vehicleNo"
            this.searchRowsInfo()
          } else {
            this.searchInfo.sortType = a.prop
            this.searchRowsInfo()
          }
        } else {
          this.searchInfo.asc = "true", this.searchInfo.sortType = ""
        }
      },


      //获取所有信息
      searchRowsInfo(val){
        val?"":this.currentPage = 1;
        this.axios.post(process.env.API_HOST + `/facilities/selectLabelGrid`, {
          page: this.currentPage,
          rows: this.pageSize,
          labelNo: this.searchInfo.labelNo,
          putDistrict: this.searchInfo.putDistrict,
          street: this.searchInfo.street,
          labelStatus: this.searchInfo.labelStatus,
        })
          .then(response => {
            const result = response.data
            if(result.code==200){
              this.rows = result.rows
              this.count = result.total;
            }
          })
      },
      handleSizeChange(val) {
        this.pageSize = val
        this.searchRowsInfo()
      },
      handleCurrentChange(val) {
        this.currentPage = val;
        this.searchRowsInfo(val)

      },
    },
  }
</script>

<style lang="stylus" rel="stylesheet/stylus">
  @import "../../../common/stylus/mixin.styl"
  .electronicTagWrap
    page()
</style>
